package stu.day39_day.day39;

import java.util.Arrays;

public class hw3 {
    public int rob(int[] nums) {
        int len = nums.length;
        if(len==1){
            return nums[0];
        }

        int[] arr = Arrays.copyOfRange(nums,0,len-1);
        int[] arr1 = new int[len-1];
        int[] arr2 = new int[len-1];
        for(int i=0;i<len-1;i++){
            arr1[i] = nums[i];
        }
        for(int i=1;i<len;i++){
            arr2[i] = nums[i];
        }

        return Math.max(rob2(arr1),rob2(arr2));


    }

    public int rob2(int[] nums) {
        int len = nums.length;
        int[] dp = new int[len];

        dp[0]=nums[0];
        for(int i=1;i<len;i++){
            if(i==1){
                dp[i] = Math.max(dp[i-1],nums[i]);
            }else {
                dp[i] = Math.max(dp[i-1],dp[i-2]+nums[i]);
            }
        }

        return dp[len-1];


    }


}
